import 'package:flutter/material.dart';
import 'package:wechat/discovery/discovery_child_page.dart';

class DiscoveryCell extends StatelessWidget {
  final String title;
  final String imageName;
  final String? subTitle;
  final String? subImageName;
  final bool showBorder;

  const DiscoveryCell({
    super.key,
    required this.title,
    required this.imageName,
    this.subTitle,
    this.subImageName,
    this.showBorder = false,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Container(
        height: 44,
        color: Colors.white,
        child: Stack(
          alignment: Alignment.center,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                // left
                Container(
                  margin: const EdgeInsets.only(left: 10),
                  child: Row(
                    children: [
                      Image.asset(imageName, width: 24),
                      const SizedBox(width: 15),
                      Text(
                        title,
                        style: const TextStyle(
                          color: Colors.black87,
                          fontSize: 14,
                          fontWeight: FontWeight.w500,
                        ),
                      )
                    ],
                  ),
                ),
                // right
                Container(
                  margin: const EdgeInsets.only(right: 10),
                  child: Row(
                    children: [
                      subTitle != null
                          ? Text(
                              subTitle!,
                              style: TextStyle(
                                fontSize: 12,
                                color: Colors.grey[800],
                              ),
                            )
                          : const Text(''),
                      subImageName != null
                          ? Image.asset(
                              'images/dot.png',
                              width: 14,
                            )
                          : const Text(''),
                      Image.asset(
                        'images/arrow_right.png',
                        width: 28,
                      )
                    ],
                  ),
                ),
              ],
            ),
            showBorder
                ? Positioned(
                    height: 0.5,
                    left: 50,
                    right: 0,
                    bottom: 0,
                    child: Container(
                        color: const Color.fromRGBO(220, 220, 220, 1)),
                  )
                : const Text(''),
          ],
        ),
      ),
      onTap: () {
        Navigator.of(context)
            .push(MaterialPageRoute(builder: (BuildContext context) {
          return DiscoveryChildPage(title: title);
        }));
      },
    );
  }
}
